/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ufps.cuatro.modelo.asistente.espejo.simple.wizard;

import com.ufps.cuatro.controlador.render.UtilRender;
import com.ufps.cuatro.modelo.representacion.componente.Componente;
import com.ufps.cuatro.util.wizard.ObjectTempSwapWizard;
import com.ufps.cuatro.util.wizard.UtilWizard;
import com.ufps.cuatro.util.wizard.WizardPanelDescriptor;
import com.ufps.cuatro.vistas.asistente.espejo.simple.wizard.JPanelWizardEspejoSimpleSelectElements;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 *
 * @author Carlos A. Torres C. 
 */
public class JPanelWizardEspejoSimpleSelectElementsDescriptor extends WizardPanelDescriptor implements ActionListener {
    
    public static final String IDENTIFIER = "SELECT_ELEMENTS";
    private JPanelWizardEspejoSimpleSelectElements objPanel;
    
    public JPanelWizardEspejoSimpleSelectElementsDescriptor() {
        objPanel = new JPanelWizardEspejoSimpleSelectElements();
        objPanel.addCheckBoxActionListener(JPanelWizardEspejoSimpleSelectElementsDescriptor.this);
        setPanelDescriptorIdentifier(IDENTIFIER);
        setPanelComponent(objPanel);
    }
    
    @Override
    public Object getNextPanelDescriptor() {
        return JPanelWizardEspejoSimpleSelectElementsDescriptor.FINISH;
    }
    
    @Override
    public Object getBackPanelDescriptor() {
        return null;
    }
    
    @Override
    public void aboutToDisplayPanel() {
        setNextButtonAccordingToCheckBox();
    }   
    
    public void actionPerformed(ActionEvent e) {
        setNextButtonAccordingToCheckBox();
    }
    
    private void setNextButtonAccordingToCheckBox() {
        if (objPanel.isCheckBoxSelected()){
            if(objPanel.isListEmpty()){
                UtilRender.msgAdvertencia("No puede generar un Componente Vacio.");
                objPanel.getjCheckBoxConfirmar().setSelected(false);
                return;
            }
            getWizard().setNextFinishButtonEnabled(true);
            procesarConfiguracion();
        }
        else{
            getWizard().setNextFinishButtonEnabled(false);             
        }           
    }     
    
    private void procesarConfiguracion() {                
        ArrayList<Componente> objComponentes = objPanel.getObjComponentes();                
        ObjectTempSwapWizard objSwap = new ObjectTempSwapWizard(UtilWizard.WIZARD_ASISTENTE_ESPEJO_SIMPLE);
        objSwap.add(ObjectTempSwapWizard.COLECCION, objComponentes);
        UtilWizard.objTempSwap = objSwap;
        UtilRender.printlnConsole("Configuración Procesada en el Objeto de Intercambio....", UtilRender.ACTION_NORMAL, true);        
    }    
}
